package com.starry.designPatterns.creatation.singleton;

public class Person {


    private String name;
    private int age;

    //分为 饿汉 懒汉
    private volatile static Person instance;

    //构造器私有 外部不可以实例化
    private Person(){

    }

    //提供给外部的方法
    //1、 public  synchronized static Person getPerson  锁太大
    //2、双重检查锁+内存可见
    public   static Person getPerson(){
        if (instance == null) {
            synchronized(Person.class) {
                if (instance == null) {
                    instance=new Person();
                }
            }

        }
        return instance;
    }
}
